package tests;

import static org.junit.Assert.*;

import java.sql.Timestamp;
import java.util.Date;


import model.Email;
import model.EmailBuilder;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
 * This class tests the Email class
 * 
 * @author buthainahaldosary
 * @since May 2013
 *
 */
public class TestEmail {

	Date date;
	int uid=2;
	Timestamp currentTime;
	EmailBuilder emb=new EmailBuilder();
	Email em;
	
	/**
	 * This method is called before every test case.
	 */
	@Before
	public void setUp()
	{
	
	 date= new Date();
	 currentTime=(new Timestamp(date.getTime()));
	 em=emb.withTo("Sara@gmail.com").withFrom("Buthainah.aldosary@gmail.com").withSubject("Hello").withBody("Just dropping by to say hello")
			 .withRead(false).withTimestamp(currentTime).withFolderId(1).build();

	}

	@After
	public void tearDown() {
		emb = null;
		em = null;
		System.gc();

	}
	
	/**
	 * This test case tests the getHashCode() method.
	 */
	@Test 
	//Re-do this.
	public void testGetHashCode() {		
		assertEquals(uid,em.getId());
	}
	/**
	 * This test case tests the setHashCode() method.
	 */
	@Test
	public void testSetHashCode() {
		
		int id=4;
		em.setId(id);
		assertEquals(id,em.getId());
	}
	/**
	 * This test case tests the getTo() method
	 */
	@Test
	public void testGetTo() {
		assertEquals("Sara@gmail.com",em.getTo());
	}
	/**
	 * This test case tests the SetTo() method
	 */
	@Test
	public void testSetTo() {
		em.setTo("Laura@gmail.com");
		assertEquals("Laura@gmail.com",em.getTo());
	}

	/**
	 * This test case tests the GetFrom() method
	 */
	@Test
	public void testGetFrom() {
		assertEquals("Buthainah.aldosary@gmail.com",em.getFrom());
	}
	/**
	 * This test case tests the SetFrom() method
	 */
	@Test
	public void testSetFrom() {
		em.setFrom("b_aldosa@concordia.ca");
		assertEquals("b_aldosa@concordia.ca",em.getFrom());
	}
	/**
	 * This test case tests the GetSubject() method
	 */
	@Test
	public void testGetSubject() {
		assertEquals("Hello",em.getSubject());
	}
	/**
	 * This test case tests the SetSubject() method
	 */
	@Test
	public void testSetSubject() {
		em.setSubject("Meeting Confirmation");
		assertEquals("Meeting Confirmation",em.getSubject());
	}
	/**
	 * This test case tests the GetBody() method
	 */
	@Test
	public void testGetBody() {
		assertEquals("Just dropping by to say hello",em.getBody());
	}
	/**
	 * This test case tests the SetBody() method
	 */
	@Test
	public void testSetBody() {
		em.setBody("Hello, I am declining the meeting tomorrow. Thank you.");
		assertEquals("Hello, I am declining the meeting tomorrow. Thank you.",em.getBody());
	}

	/**
	 * This test case tests the IsRead() method
	 */
	@Test
	public void testIsRead() {
		assertEquals(false,em.isRead());
	}
	/**
	 * This test case tests the SetRead() method
	 */
	@Test
	public void testSetRead() {
		em.setRead(true);
		assertEquals(true,em.isRead());
	}
	/**
	 * This test case tests the GetTimestamp() method
	 */
	@Test
	public void testGetTimestamp() {
		Date date= new Date();
		Timestamp currentTime=(new Timestamp(date.getTime()));
		em.setTimestamp(currentTime);
		assertEquals(currentTime,em.getTimestamp());
	}
	/**
	 * This test case tests the SetTimestamp() method
	 */
	@Test
	public void testSetTimestamp() {
		Date date= new Date();
		Timestamp currentTime=(new Timestamp(date.getTime()));
		em.setTimestamp(currentTime);
		assertEquals(currentTime,em.getTimestamp());
	}
	/**
	 * This test case tests the GetCurrentFolder() method
	 */
	@Test
	public void testGetCurrentFolder() {
		
		assertEquals(1,em.getFolderId());
	}
	/**
	 * This test case tests the SetCurrentFolder() method
	 */
	@Test
	public void testSetCurrentFolder() {
		
		em.setFolderId(3);
		assertEquals(3,em.getFolderId());
	}
	/**
	 * This test case tests the ToString() method
	 */
	//Update as necessary
	@Test
	public void testToString() {
		fail("Not yet implemented");
	}

}
